package com.zhkjnet.zhyy.service;

import com.zhkjnet.zhyy.dao.RechargeRecordDao;
import com.zhkjnet.zhyy.entity.RechargeRecord;
import com.zhkjnet.zhyy.entity.RechargeStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class RechargeRecordService {

    @Autowired
    private RechargeRecordDao recordDao;

    @Transactional
    public void save(RechargeRecord record) {
        record.setStatus(RechargeStatus.Submit);
        record.setCreateTime(new Date());
        recordDao.save(record);
    }

    public List<RechargeRecord> findAllSuccessBefore30Day() {
        return recordDao.findAllSuccessBefore30Day();
    }

    public List<RechargeRecord> findAllSubmit() {
        return recordDao.findAllSubmit();
    }

    @Transactional
    public void update(RechargeRecord record) {
        recordDao.update(record);
    }

    public List<RechargeRecord> findAll(Long page, Integer length) {
        return recordDao.findAll((page - 1) * length, length);
    }

    public Long count() {
        return recordDao.count();
    }

    public List<RechargeRecord> findAllSingle() {
        return recordDao.findAllSingle();
    }

    @Transactional
    public void updateAllMin() {
        recordDao.updateAllMin();
    }
}
